package com.itcast.mallapplet.mapper;

import com.itcast.admin.vo.OrderAllVO;
import com.itcast.applet.entity.Order;
import com.itcast.applet.entity.OrderDity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper {

    //新增订单主表
    @Insert("insert into `order`(user_id, address_id, order_id, number, price, create_time, status) " +
            "values (#{userId},#{addressId},#{orderId},#{number}, #{price},#{createTime},#{status}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void orderAdd(Order order);

    //新增订单分表数据
    @Insert("insert into order_dity(name, number, price, shop_id, order_id,present) values (#{name},#{number},#{price},#{shopId},#{orderId},#{present})")
    void orderDity(OrderDity orderDity);

    //根据id查询订单表
    @Select("select id, user_id, address_id, order_id, number, price, create_time, update_time, status from `order` where id = #{id}")
    Order orderGetById(Long id);

    //根据订单id查询订单分表数据
    OrderDity orderGetByDityId(Long id);

    //查询该用户的全部订单
    List<OrderAllVO> orderQueryAll(Long currentId);

    //订单退款
    void orderRefund(Order order);

    //订单完成
    void riderOrder(Long id);

    @Select("select * from order_dity where order_id = #{id}")
    List<OrderDity> orderDityAll(Long id);

    void amendStatus(Order order);
}
